package com.owbtgad.common.base

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.Fragment

/**
 * 创建日期 2020/9/24
 * 描述：
 */
abstract class BaseFragment : Fragment() {
    val TAG = this.javaClass.simpleName
    protected var mContext: Context? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mContext = context
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(getContentLayout(), container, false)
    }

    protected abstract fun getContentLayout(): Int
    override fun onDestroy() {
        super.onDestroy()
    }

    protected fun finish() {
        activity?.finish()
    }

    fun closeKeyboard() {
        val view = activity!!.window.peekDecorView()
        if (view != null) {
            val inputMethodManager =
                activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }
}